import {defHttp} from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";

const { createConfirm } = useMessage();

enum Api {
  list = '/ps/psPrePlanningScheduling/list',
  save='/ps/psPrePlanningScheduling/add',
  edit='/ps/psPrePlanningScheduling/edit',
  deleteOne = '/ps/psPrePlanningScheduling/delete',
  deleteBatch = '/ps/psPrePlanningScheduling/deleteBatch',
  importExcel = '/ps/psPrePlanningScheduling/importStation',
  exportXls = '/ps/psPrePlanningScheduling/exportXls',
  psPlanningSchedulingOrderContentList = '/ps/psPrePlanningScheduling/queryPsPrePlanningSchedulingOrderContentByMainId',
  psPlanningSchedulingAvailableResourcesList = '/ps/psPrePlanningScheduling/queryPsPrePlanningSchedulingAvailableResourcesByMainId',
  psPlanningSchedulingProcessDetailList = '/ps/psPrePlanningScheduling/queryPsPrePlanningSchedulingAvailableResourcesByMainId',
  queryArrangementItemByMainIds = '/ps/psProductionArrangementPlans/queryItemByMainIds',
  queryMpsItemByMainIds = '/psProductionPlanMps/queryItemByMainIds',
  distribute = '/ps/psPrePlanningScheduling/distribute',
  simulatedScheduling = '/ps/psProductionArrangementImitatePlans/all',
  preCalculate ='/ps/psPrePlanningScheduling/calculate',
  schedulingList = '/ps/psPrePlanningScheduling/pre/list',
  schedulingAdd = "/ps/psPrePlanningScheduling/add",
  schedulingDel = "/ps/psPrePlanningScheduling/delete",
  schedulingEdit = "/ps/psPrePlanningScheduling/edit",
  distributeMRP = "/ps/psPrePlanningScheduling/distributeMRP",
  gerProductionSchedulingLogList = '/ps/psPreProductionArrangementPlansResult/list'
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
// 排产日志
export const gerProductionSchedulingLogList = (params) =>
  defHttp.get({ url: Api.gerProductionSchedulingLogList, params }, { joinParamsToUrl: true });
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
// 根据生产主计划id集合批量查询明细
export const getMpsItemByMainIds = (params) =>
  defHttp.get({url: Api.queryMpsItemByMainIds, params});
/**
 * 查询子表数据
 * @param params
 */
export const psPlanningSchedulingOrderContentList = Api.psPlanningSchedulingOrderContentList;
/**
 * 查询子表数据
 * @param params
 */
export const psPlanningSchedulingAvailableResourcesList = Api.psPlanningSchedulingAvailableResourcesList;
/**
 * 查询子表数据
 * @param params
 */
export const psPlanningSchedulingProcessDetailList = Api.psPlanningSchedulingProcessDetailList;
/**
 * 列表接口
 * @param params
 */
// 根据总装排查计划id集合批量查询明细
export const getArrangementItemByMainIds = (params) =>
  defHttp.get({url: Api.queryArrangementItemByMainIds, params});

// 排产作业        
export const preCalculate = (params) =>
  defHttp.post({url: Api.preCalculate,params});

// 排产工作台详情-查询
export const schedulingList = (params) =>
  defHttp.post({url: Api.schedulingList, params}, {joinParamsToUrl: true});
// 排产工作详情-添加
// export const schedulingAdd = (params) =>
//   defHttp.post({url: Api.schedulingAdd, params});
// 排产工作详情-删除
export const schedulingDel = (params) =>
  defHttp.post({url: Api.schedulingDel, params});
// 排产工作详情-编辑
// export const schedulingEdit = (params) =>
//   defHttp.post({url: Api.schedulingEdit, params});
/**
 * 计划下发
 */
export const distributePlan = (params) =>
  defHttp.post({url: Api.distribute, params});
export const list = (params) =>
  defHttp.get({url: Api.list, params});
/**
 * 删除单个
 */
export const deleteOne = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}
/**
 * 批量删除
 * @param params
 */
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.schedulingEdit : Api.schedulingAdd;
  return defHttp.post({url: url, params});
}
export const distributeMRP = (data) => {
  return defHttp.post({url: Api.distributeMRP, data});
}
